package Practice08;

public class DemoString {
    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        String s3 = "word";
        // equals
        System.out.println(s1.equals(s3));
        // length
        System.out.println(s1.length());
        // concat
        System.out.println(s1.concat(s3));
        // indexOf
        System.out.println(s1.concat(s3).indexOf("ord"));
        // substring
        System.out.println(s1.substring(3));
        // toCharArray()
        char[] chs = s1.toCharArray();
        for (int i = 0; i < chs.length; i++) {
            System.out.println("chs[i]" + chs[i]);
        }
        // getBytes()
        byte[] bys = s1.getBytes();
        for (int j = 0; j < bys.length; j++) {
            System.out.println(bys[j]);
        }
        // replace
        String replace = s1.replace("h", "H");
        System.out.println("replace:" + replace);
        // split
        String st1 = "a|b|c|d";
        String[] strArray = st1.split("|");
        System.out.println(strArray.length + "  length");
        for (int i = 0; i < strArray.length; i++) {
            System.out.println(strArray[i]);
        }

        int[] arr = {1, 2, 3};
        String s = arryToSting(arr);
        System.out.println(s+"s:");

    }


    public static String arryToSting(int[] arr) {
        String s = "[";
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                s = s.concat(arr[i] + "]");
            } else {
                s = s.concat(arr[i] + "#");
            }
        }
        return s;
    }
}
